package com.szqhyxj.youxiangju.biz.partnerHome.home.partnerdetails;

import com.szqhyxj.youxiangju.sys.BaseResult;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by leung on 2018/11/21.
 */

public class PartnerDetailsPresenter implements PartnerDetailsContract.Presenter {
    PartnerDetailsContract.View view;

    public PartnerDetailsPresenter(PartnerDetailsContract.View view) {
        this.view = view;
    }

    @Override
    public void onDestroy() {

    }

    @Override
    public void init(String organId, int organType, int statisticsType) {
        PartnerDetailsModel.getpartnerDetails(organId, organType, statisticsType)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(new Consumer<BaseResult<PartnerDetailsModel.PartnerDetailsEntity>>() {
                    @Override
                    public void accept(BaseResult<PartnerDetailsModel.PartnerDetailsEntity> partnerDetailsEntityBaseResult) throws Exception {
                        if (partnerDetailsEntityBaseResult.businessLogicSuccess()) {
                            view.showInfo(partnerDetailsEntityBaseResult.getData());
                        } else {
                            view.showToast(partnerDetailsEntityBaseResult.getData() + "");
                        }
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        view.showToast(throwable.getMessage());
                    }
                });
    }
}
